package com.xjscrm.console.service.customer.operatePlan.impl;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.xjscrm.common.constant.ResponseMsg;
import com.xjscrm.common.entity.*;
import com.xjscrm.common.enums.RedisCacheKeyEnum;
import com.xjscrm.common.exception.BusinessException;
import com.xjscrm.common.result.ResponseCode;
import com.xjscrm.common.utils.DateUtil;
import com.xjscrm.common.utils.OrderByUtil;
import com.xjscrm.common.vo.grouppull.GroupPullData;
import com.xjscrm.common.vo.grouppull.GroupRule;
import com.xjscrm.common.vo.grouppull.GroupRuleInfo;
import com.xjscrm.common.vo.operatorplandevice.OperatorPlanDeviceRule;
import com.xjscrm.console.mapper.GroupPullConfigDeviceMapper;
import com.xjscrm.console.mapper.GroupPullConfigMapper;
import com.xjscrm.console.mapper.WwCustomerMapper;
import com.xjscrm.console.mapper.WwDeviceMapper;
import com.xjscrm.console.param.operatePlan.*;
import com.xjscrm.console.param.wwCustomer.CustomerQuery;
import com.xjscrm.console.param.wwDevice.WwDeviceQuery;
import com.xjscrm.console.service.customer.operatePlan.GroupPullService;
import com.xjscrm.console.vo.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class GroupPullServiceImpl implements GroupPullService {

    @Autowired
    private GroupPullConfigMapper groupPullConfigMapper;

    @Autowired
    private GroupPullConfigDeviceMapper groupPullConfigDeviceMapper;

    @Autowired
    private WwDeviceMapper wwDeviceMapper;

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private WwCustomerMapper wwCustomerMapper;

    @Override
    public Long addGroupPullPlan(GroupPullDto groupPullDto) {
        if(groupPullDto.getMerId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        GroupPullConfig groupPullConfig = new GroupPullConfig();
        BeanUtil.copyProperties(groupPullDto,groupPullConfig);
        int time = DateUtil.getTime();
        Long sixDigitsNum = getSixDigitsNum();
        groupPullConfig.setId(sixDigitsNum);
        groupPullConfig.setCreateTime(time);
        groupPullConfig.setUpdateTime(time);

        if(groupPullDto.getModel()!=null&&groupPullDto.getModel()==0&&groupPullDto.getGroupPullDataList()!=null&&!groupPullDto.getGroupPullDataList().isEmpty()){
            groupPullConfig.setGuider(JSONObject.toJSONString(groupPullDto.getGroupPullDataList()));

        }
        if(groupPullDto.getModel()!=null&&groupPullDto.getModel()==0&&groupPullDto.getGroupPullData()!=null){
            groupPullConfig.setRule(JSONObject.toJSONString(groupPullDto.getGroupPullData()));
        }
        if(groupPullDto.getModel()!=null&&groupPullDto.getModel()==1&&groupPullDto.getGroupRuleList()!=null&&!groupPullDto.getGroupRuleList().isEmpty()){
            groupPullConfig.setGroupRules(JSONObject.toJSONString(groupPullDto.getGroupRuleList()));
        }
        groupPullConfigMapper.insert(groupPullConfig);

        return sixDigitsNum;
    }

    @Override
    public Object getGroupPullPlanList(GroupPullQuery groupPullQuery) {
        if(groupPullQuery.getMerId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        String orderBy = OrderByUtil.getOrderBy(groupPullQuery.getOrderByField(), groupPullQuery.isAsc());
        PageHelper.startPage(groupPullQuery.getCurrent(),groupPullQuery.getSize(),orderBy);
        List<GroupPullVo> groupPullVoList=groupPullConfigMapper.getGroupPullPlanList(groupPullQuery);
        return new MyPageInfo<>(groupPullVoList);
    }

    @Override
    public Object getGroupPullPlanDetail(GroupPullDto groupPullDto) {
        if(groupPullDto.getMerId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        if(groupPullDto.getId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.ID_NULL);
        }
        GroupPullConfig groupPullConfig=  groupPullConfigMapper.getById(groupPullDto.getId(),groupPullDto.getMerId());
        if(groupPullConfig==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该方案不存在");
        }
        GroupPullVo groupPullVo = new GroupPullVo();
        BeanUtil.copyProperties(groupPullConfig,groupPullVo);

        if(groupPullVo.getModel()!=null&&groupPullVo.getModel()==0&&!StringUtils.isBlank(groupPullVo.getGuider())){
            groupPullVo.setGroupPullDataList(JSONObject.parseArray(groupPullVo.getGuider(), GroupPullData.class));

        }
        if(groupPullVo.getModel()!=null&&groupPullVo.getModel()==0&&!StringUtils.isBlank(groupPullVo.getRule())){
            groupPullVo.setGroupPullData(JSONObject.parseObject(groupPullVo.getRule(),GroupPullData.class));
        }
        if(groupPullConfig.getModel()!=null&&groupPullConfig.getModel()==1&&!StringUtils.isBlank(groupPullVo.getGroupRules())){
            groupPullVo.setGroupRuleList(JSONObject.parseArray(groupPullVo.getGroupRules(), GroupRule.class));
        }

        if(groupPullVo.getGroupRuleList()!=null&&!groupPullVo.getGroupRuleList().isEmpty()){
            for (GroupRule groupRule:groupPullVo.getGroupRuleList()) {
                WwDevice wwDevice = wwDeviceMapper.getById(groupRule.getDeviceUniqueId(), groupPullVo.getMerId());
                groupRule.setDeviceId(wwDevice.getDeviceId());
                groupRule.setDeviceHeadImageUrl(wwDevice.getHeadImgUrl());

                try {
                    if(groupRule.getCustomerIds()!=null&&!groupRule.getCustomerIds().isEmpty()){
                        List<WwCustomer> wwGroupVoList=new ArrayList<>();
                        for (Long customerId:groupRule.getCustomerIds()) {
                            WwCustomer wwCustomer = wwCustomerMapper.getById(customerId, groupPullVo.getMerId());
                            if(wwCustomer!=null){
                                wwGroupVoList.add(wwCustomer);
                            }
                        }
                        if(!wwGroupVoList.isEmpty()){
                            groupRule.setWwCustomerList(wwGroupVoList);
                        }
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }



        if(groupPullVo.getGroupPullData()!=null&&groupPullVo.getGroupPullData().getGroupRules()!=null&&!groupPullVo.getGroupPullData().getGroupRules().isEmpty()){
            for (GroupRule groupRule:groupPullVo.getGroupPullData().getGroupRules()) {
                try {
                    if(groupRule.getCustomerIds()!=null&&!groupRule.getCustomerIds().isEmpty()){
                        List<WwCustomer> wwGroupVoList=new ArrayList<>();
                        for (Long customerId:groupRule.getCustomerIds()) {
                            WwCustomer wwCustomer = wwCustomerMapper.getById(customerId, groupPullVo.getMerId());
                            if(wwCustomer!=null){
                                wwGroupVoList.add(wwCustomer);
                            }
                        }
                        if(!wwGroupVoList.isEmpty()){
                            groupRule.setWwCustomerList(wwGroupVoList);
                        }
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
        return groupPullVo;
    }

    @Override
    public void updateGroupPullPlan(GroupPullDto groupPullDto) {
        if(groupPullDto.getMerId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        if(groupPullDto.getId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.ID_NULL);
        }
        GroupPullConfig groupPullConfig=  groupPullConfigMapper.getById(groupPullDto.getId(),groupPullDto.getMerId());
        if(groupPullConfig==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该方案不存在");
        }

        BeanUtil.copyProperties(groupPullDto,groupPullConfig);
        if(groupPullDto.getModel()!=null&&groupPullDto.getModel()==0&&groupPullDto.getGroupPullDataList()!=null&&!groupPullDto.getGroupPullDataList().isEmpty()){
            groupPullConfig.setGuider(JSONObject.toJSONString(groupPullDto.getGroupPullDataList()));

        }
        if(groupPullDto.getModel()!=null&&groupPullDto.getModel()==0&&groupPullDto.getGroupPullData()!=null){
            GroupPullData groupPullData=JSONObject.parseObject(groupPullConfig.getRule(),GroupPullData.class);
            //创建新群名称开始编号 重制后清除缓存
            if(groupPullData!=null&&groupPullDto.getGroupPullData().getCreateGroupNameStartNo()!=null&&groupPullData.getCreateGroupNameStartNo()!=null&&!groupPullData.getCreateGroupNameStartNo().equals(groupPullDto.getGroupPullData().getCreateGroupNameStartNo())){

                GroupPullDeviceQuery groupPullDeviceQuery=new GroupPullDeviceQuery();
                groupPullDeviceQuery.setPlanId(groupPullConfig.getId());
                groupPullDeviceQuery.setMerId(groupPullConfig.getMerId());
                List<GroupPullConfigDeviceVo> groupPullConfigDeviceVoList = groupPullConfigDeviceMapper.getDelPlanDeviceList(groupPullDeviceQuery);
                if(groupPullConfigDeviceVoList!=null&&!groupPullConfigDeviceVoList.isEmpty()){
                    for (GroupPullConfigDeviceVo groupPullConfigDeviceVo:groupPullConfigDeviceVoList) {
                        try {
                            redisTemplate.delete(String.format(RedisCacheKeyEnum.GROUP_PULL_GROUP_NAME_START_NO.getKey(),groupPullData.getGroupPullKey(),groupPullConfigDeviceVo.getDeviceUniqueId()));
                        }catch (Exception e){
                            e.printStackTrace();
                        }

                    }
                }
            }

            groupPullConfig.setRule(JSONObject.toJSONString(groupPullDto.getGroupPullData()));
        }
        if(groupPullDto.getModel()!=null&&groupPullDto.getModel()==1&&groupPullDto.getGroupRuleList()!=null&&!groupPullDto.getGroupRuleList().isEmpty()){
            groupPullConfig.setGroupRules(JSONObject.toJSONString(groupPullDto.getGroupRuleList()));
        }
        groupPullConfigMapper.update(groupPullConfig);

    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delGroupPullPlan(GroupPullDto groupPullDto) {
        if(groupPullDto.getMerId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        if(groupPullDto.getId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.ID_NULL);
        }
        GroupPullConfig groupPullConfig=  groupPullConfigMapper.getById(groupPullDto.getId(),groupPullDto.getMerId());
        if(groupPullConfig==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该方案不存在");
        }

        //查询方案和机器人关系  删除
        GroupPullDeviceQuery groupPullDeviceQuery=new GroupPullDeviceQuery();
        groupPullDeviceQuery.setMerId(groupPullConfig.getMerId());
        groupPullDeviceQuery.setPlanId(groupPullConfig.getId());
        List<GroupPullConfigDeviceVo> delPlanDeviceList = groupPullConfigDeviceMapper.getDelPlanDeviceList(groupPullDeviceQuery);
        if(delPlanDeviceList!=null&&!delPlanDeviceList.isEmpty()){
            delPlanDeviceList.forEach(it->groupPullConfigDeviceMapper.delById(it.getId(),it.getMerId()));
        }

        //删除方案
        groupPullConfigMapper.delById(groupPullConfig.getId(),groupPullConfig.getMerId());
    }

    @Override
    public void addPlanDevice(BatchAddGroupPullPlanDeviceDto batchAddGroupPullPlanDeviceDto) {
        if(batchAddGroupPullPlanDeviceDto.getMerId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        if(batchAddGroupPullPlanDeviceDto.getPlanId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }
        if(batchAddGroupPullPlanDeviceDto.getDeviceUniqueId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }
        GroupPullConfig groupPullConfig = groupPullConfigMapper.getById(batchAddGroupPullPlanDeviceDto.getPlanId(), batchAddGroupPullPlanDeviceDto.getMerId());

        if(groupPullConfig==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该方案不存在");
        }
        GroupPullConfigDevice groupPullConfigDevice=new GroupPullConfigDevice();
        groupPullConfigDevice.setMerId(groupPullConfig.getMerId());
        groupPullConfigDevice.setPlanId(groupPullConfig.getId());
        groupPullConfigDevice.setType(groupPullConfig.getType());
        groupPullConfigDevice.setDeviceUniqueId(batchAddGroupPullPlanDeviceDto.getDeviceUniqueId());
        groupPullConfigDeviceMapper.add(groupPullConfigDevice);
    }

    @Override
    public void delPlanDevice(BatchAddGroupPullPlanDeviceDto batchAddGroupPullPlanDeviceDto) {
        if(batchAddGroupPullPlanDeviceDto.getMerId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        if(batchAddGroupPullPlanDeviceDto.getId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.ID_NULL);
        }

        groupPullConfigDeviceMapper.delById(batchAddGroupPullPlanDeviceDto.getId(),batchAddGroupPullPlanDeviceDto.getMerId());
    }

    @Override
    public void updatePlanDevice(BatchAddGroupPullPlanDeviceDto batchAddGroupPullPlanDeviceDto) {
        if(batchAddGroupPullPlanDeviceDto.getMerId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        if(batchAddGroupPullPlanDeviceDto.getId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.ID_NULL);
        }
        if(batchAddGroupPullPlanDeviceDto.getSleepRule()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }
        GroupPullConfigDevice groupPullConfigDevice= groupPullConfigDeviceMapper.getById(batchAddGroupPullPlanDeviceDto.getId(),batchAddGroupPullPlanDeviceDto.getMerId());

        if(groupPullConfigDevice==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该机器人应用列表不存在");
        }

        groupPullConfigDevice.setRule(JSONObject.toJSONString(batchAddGroupPullPlanDeviceDto.getSleepRule()));
        groupPullConfigDeviceMapper.update(groupPullConfigDevice);
    }


    @Override
    public Object getDelPlanDeviceList(GroupPullDeviceQuery groupPullDeviceQuery) {
        if(groupPullDeviceQuery.getMerId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        //关键词参数
        //关键词中有机器人ID或者机器人的name
        List<Long> getDeviceUniqueIds=new ArrayList<>();
        if(!StringUtils.isBlank(groupPullDeviceQuery.getKeyword())){
            //机器人ID
            WwDeviceQuery wwDeviceQuery=new WwDeviceQuery();
            wwDeviceQuery.setMerId(groupPullDeviceQuery.getMerId());
            wwDeviceQuery.setKeyword(groupPullDeviceQuery.getKeyword());
            List<WwDeviceVo> wwDeviceList = wwDeviceMapper.getWwDeviceList(wwDeviceQuery);
            if(wwDeviceList!=null&&!wwDeviceList.isEmpty()){
                wwDeviceList.forEach(it->getDeviceUniqueIds.add(it.getId()));
            }
            if(getDeviceUniqueIds.isEmpty()){
                return  new MyPageInfo<>(null);
            }
            groupPullDeviceQuery.setDeviceUniqueIds(getDeviceUniqueIds);
        }

        String orderBy = OrderByUtil.getOrderBy(groupPullDeviceQuery.getOrderByField(), groupPullDeviceQuery.isAsc());
        PageHelper.startPage(groupPullDeviceQuery.getCurrent(),groupPullDeviceQuery.getSize(),orderBy);

        List<GroupPullConfigDeviceVo> groupPullConfigDeviceVoList= groupPullConfigDeviceMapper.getDelPlanDeviceList(groupPullDeviceQuery);
        if(groupPullConfigDeviceVoList==null||groupPullConfigDeviceVoList.isEmpty()){
            return  new MyPageInfo<>(null);
        }

        for (GroupPullConfigDeviceVo groupPullConfigDeviceVo : groupPullConfigDeviceVoList) {
              try {
                  if(!StringUtils.isBlank(groupPullConfigDeviceVo.getRule())){
                      groupPullConfigDeviceVo.setSleepRule(JSONObject.parseObject(groupPullConfigDeviceVo.getRule(), OperatorPlanDeviceRule.class));
                  }
                  WwDevice wwDevice = wwDeviceMapper.getById(groupPullConfigDeviceVo.getDeviceUniqueId(), groupPullConfigDeviceVo.getMerId());
                  groupPullConfigDeviceVo.setDeviceName(wwDevice.getDeviceName());
                  groupPullConfigDeviceVo.setHeadImageUrl(wwDevice.getHeadImgUrl());
              }catch (Exception e){
                  e.printStackTrace();
              }
        }

        return new MyPageInfo<>(groupPullConfigDeviceVoList);
    }


    @Override
    public Object findAddFangetEffectuateGroupGroup(EffectuateGroupDto effectuateGroupDto) {
        if(effectuateGroupDto.getMerId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        if(effectuateGroupDto.getPlanId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }
        if(StringUtils.isBlank(effectuateGroupDto.getGroupPullKey())){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }
        GroupPullConfig groupPullConfig = groupPullConfigMapper.getById(effectuateGroupDto.getPlanId(), effectuateGroupDto.getMerId());
        if(groupPullConfig==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该方案不存在");
        }
        if(StringUtils.isBlank(groupPullConfig.getGuider())){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该方案引导语不存在");
        }
        List<GroupPullData> groupPullDataList = JSONObject.parseArray(groupPullConfig.getGuider(), GroupPullData.class);
        if(groupPullDataList==null||groupPullDataList.isEmpty()){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该方案引导语不存在");
        }
        List<EffectuateGroupVo> effectuateGroupVoList=new ArrayList<>();

        for (GroupPullData groupPullData:groupPullDataList) {
            if(groupPullData.getMsgType()!=null&&groupPullData.getMsgType().equals(100)){
               if(!StringUtils.isBlank(groupPullData.getGroupPullKey())&&groupPullData.getGroupPullKey().equals(effectuateGroupDto.getGroupPullKey())){

                  if(groupPullData.getGroupRules()!=null&&!groupPullData.getGroupRules().isEmpty()){
                      effectuateGroupVoList=new ArrayList<>();
                      for (GroupRule groupRule:groupPullData.getGroupRules()) {
                          EffectuateGroupVo effectuateGroupVo = new EffectuateGroupVo();
                          effectuateGroupVo.setDeviceId(groupRule.getDeviceId());
                          effectuateGroupVo.setDeviceUniqueId(groupRule.getDeviceUniqueId());
                          effectuateGroupVo.setDeviceName(groupRule.getDeviceName());
                          effectuateGroupVo.setDeviceHeadImageUrl(groupRule.getDeviceHeadImageUrl());
                          if(groupRule.getGroupRuleInfos()!=null&&!groupRule.getGroupRuleInfos().isEmpty()){
                              List<GroupRuleInfoVo> groupRuleInfoVoList=new ArrayList<>();
                              for (GroupRuleInfo groupRuleInfo:groupRule.getGroupRuleInfos()) {
                                  GroupRuleInfoVo groupRuleInfoVo = new GroupRuleInfoVo();
                                  groupRuleInfoVo.setDeviceId(groupRule.getDeviceId());
                                  groupRuleInfoVo.setDeviceUniqueId(groupRule.getDeviceUniqueId());
                                  groupRuleInfoVo.setDeviceName(groupRule.getDeviceName());
                                  groupRuleInfoVo.setGroupId(groupRuleInfo.getGroupId());
                                  groupRuleInfoVo.setGroupWxid(groupRuleInfo.getGroupWxid());
                                  groupRuleInfoVo.setGroupNick(groupRuleInfo.getGroupNick());
                                  groupRuleInfoVo.setGenders(groupRuleInfo.getGenders());
                                  groupRuleInfoVo.setDeviceHeadImageUrl(groupRule.getDeviceHeadImageUrl());
                                  groupRuleInfoVo.setGroupMemberNum((Integer) redisTemplate.opsForValue().get(String.format(RedisCacheKeyEnum.GROUP_MEMBER_COUNT.getKey(),groupRuleInfo.getGroupWxid())));
                                  groupRuleInfoVoList.add(groupRuleInfoVo);
                              }
                              effectuateGroupVo.setGroupRuleInfoVoList(groupRuleInfoVoList);
                          }
                          effectuateGroupVoList.add(effectuateGroupVo);
                      }

                  }
               }
            }
        }

        return effectuateGroupVoList;
    }


    @Override
    public Object getUsedDeviceUniqueIds(GroupPullDto groupPullDto) {
        if(groupPullDto.getMerId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        if(groupPullDto.getId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.ID_NULL);
        }
        GroupPullConfig groupPullConfig = groupPullConfigMapper.getById(groupPullDto.getId(), groupPullDto.getMerId());

        if(groupPullConfig==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该方案不存在");
        }
        GroupPullDeviceQuery groupPullDeviceQuery=new GroupPullDeviceQuery();
        groupPullDeviceQuery.setMerId(groupPullDto.getMerId());
        groupPullDeviceQuery.setPlanId(groupPullDto.getId());
        List<GroupPullConfigDeviceVo> groupPullConfigDeviceVoList = groupPullConfigDeviceMapper.getDelPlanDeviceList(groupPullDeviceQuery);


        if(groupPullConfigDeviceVoList!=null&&!groupPullConfigDeviceVoList.isEmpty()){
            List<Long> collect = groupPullConfigDeviceVoList.stream().map(GroupPullConfigDeviceVo::getDeviceUniqueId).distinct().collect(Collectors.toList());
            return collect;
        }else {
            return null;
        }
    }

    private Long getSixDigitsNum(){
        return  (long) ((Math.random() * 9 + 1) * 100000);
    }
}
